$(function(){
	$.ajax({
		url:BASE_PATH+'/monit/sys.do',
		type:'get',
		dataType:'json',
		success:function(data){
			if(data.status='success'){
				if(data){
					$("#hostname").html(data.hostName);
					$("#name").html(data.name);
					$("#version").html(data.version);
					$("#arch").html(data.arch);
				}
				if(data.memory){
					$("#total").html(data.memory.total+"M");
					$("#used").html(data.memory.used+"M");
					$("#free").html(data.memory.free+"M");
					var t1 = Number(data.memory.used)/Number(data.memory.total);
					var t1c = "progress-bar-success";
					if(t1>0.5&&t1<=0.8){
						t1c = "progress-bar-warning";
					}
					if(t1>0.8){
						t1c = "progress-bar-danger";
					}
					t1 = (t1*100).toFixed(2);
					$("#t1").css("width",t1+"%");
					$("#usage").html(t1+"%");
					$("#t1").removeClass("progress-bar-success").removeClass("progress-bar-warning").removeClass("progress-bar-danger").addClass(t1c);
					$("#jvmMax").html(data.memory.jvmMax+"M");
					$("#jvmTotal").html(data.memory.jvmTotal+"M");
					$("#jvmFree").html(data.memory.jvmFree+"M");
					$("#jvmMaxFree").html(data.memory.jvmMaxFree+"M");
					var used = Number(data.memory.jvmTotal)-Number(data.memory.jvmFree);
					var t2 = Number(used)/Number(data.memory.jvmMax);
					var t2c = "progress-bar-success";
					if(t2>0.5&&t2<=0.8){
						t2c = "progress-bar-warning";
					}
					if(t2>0.8){
						t2c = "progress-bar-danger";
					}
					t2 = (t2*100).toFixed(2);
					$("#t2").css("width",t2+"%");
					$("#jvmUsage").html(t2+"%");
					$("#t2").removeClass("progress-bar-success").removeClass("progress-bar-warning").removeClass("progress-bar-danger").addClass(t2c);
					$("#swapTotal").html(data.memory.swapTotal+"M");
					$("#swapUsed").html(data.memory.swapUsed+"M");
					$("#swapFree").html(data.memory.swapFree+"M");
					var t3 = Number(data.memory.swapUsed)/Number(data.memory.swapTotal);
					var t3c = "progress-bar-success";
					if(t3>0.5&&t3<=0.8){
						t3c = "progress-bar-warning";
					}
					if(t3>0.8){
						t3c = "progress-bar-danger";
					}
					t3 = (t3*100).toFixed(2);
					$("#t3").css("width",t3+"%");
					$("#swapUsage").html(t3+"%");
					$("#t3").removeClass("progress-bar-success").removeClass("progress-bar-warning").removeClass("progress-bar-danger").addClass(t3c);
				}
				if(data.disk){
					var html = "";
					for(var i = 0; i < data.disk.length; i++){
						var t = Number(data.disk[i].used)/Number(data.disk[i].total);
						var tc = "progress-bar-success";
						if(t>0.5&&t<=0.8){
							tc = "progress-bar-warning";
						}
						if(t>0.8){
							tc = "progress-bar-danger";
						}
						t = (t*100).toFixed(2);
						html+="<div class='profile-info-row'>"
							+	  "<div class='profile-info-name'>使用情况</div>"
							+	  "<div class='profile-info-value'>"
							+		"<div class='clearfix'>"
							+  			"<span class='pull-left'>已用</span>"
							+  			"<span class='pull-right'>"+t+"%</span>"
							+		"</div>"
							+		"<div class='progress progress-mini progress-striped active'>"
							+  			"<div style='width:"+t+"%' class='progress-bar "+tc+"'></div>"
							+		"</div>"
							+	  "</div>"
							+	"</div>"
							+ "<div class='profile-info-row'>"
							+	  "<div class='profile-info-name'>磁盘名</div>"
							+	  "<div class='profile-info-value'>"
							+	  "  <span class='editable editable-click'>"+data.disk[i].devName+"</span>"
							+	  "</div>"
							+	"</div>"
							+ "<div class='profile-info-row'>"
							+	  "<div class='profile-info-name'>磁盘大小</div>"
							+	  "<div class='profile-info-value'>"
							+	  "  <span class='editable editable-click'>"+data.disk[i].total+"M</span>"
							+	  "</div>"
							+	"</div>"
							+ "<div class='profile-info-row'>"
							+	  "<div class='profile-info-name'>已用空间</div>"
							+	  "<div class='profile-info-value'>"
							+	  "  <span class='editable editable-click'>"+data.disk[i].used+"M</span>"
							+	  "</div>"
							+	"</div>"
							+ "<div class='profile-info-row'>"
							+	  "<div class='profile-info-name'>剩余空间</div>"
							+	  "<div class='profile-info-value'>"
							+	  "  <span class='editable editable-click'>"+data.disk[i].free+"M</span>"
							+	  "</div>"
							+	"</div>";
					}
					$("#disk").html(html);
				}
			}else{
				if(data.errorMsg=='expire'){
					window.location.href="login.html"
				}else{
					alert(data.erroeMsg);
				}
			}
		}
	});
});